package com.ruoyi.common.vip.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.vip.entity.YytDeliveryDate;
import com.ruoyi.common.vip.service.YytDeliveryDateService;
import com.ruoyi.utils.ResponseResult;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author MrPing
 * @since 2022-07-18
 */
@RestController
@RequestMapping("/delivery")
public class YytDeliveryDateController {

    @Autowired
    private YytDeliveryDateService yytDeliveryDateService;

    /**
     * 获取会员可配送日期
     * @return
     */
    @GetMapping("/getDeliveryDate")
    public ResponseResult getDeliveryDate() throws ParseException {

        return ResponseResult.success(yytDeliveryDateService.getDeliverDate());
    }


    /**
     * 获取普通会员配送日期
     * @return
     */
    @GetMapping("/getDeliveryDateList")
    public ResponseResult getDeliveryDateList(){
        QueryWrapper<YytDeliveryDate> wrapper = new QueryWrapper<>();
        wrapper.eq("type", 0).gt("set_send_date", LocalDate.now()).orderByDesc("set_send_date");
        List<YytDeliveryDate> list = yytDeliveryDateService.list(wrapper);
        List<String> result = new ArrayList<>();
        for (YytDeliveryDate yd : list){
            result.add(yd.getSetSendDate().toString());
        }
        return ResponseResult.success(result);
    }

}
